import 'package:flutter/material.dart';
import 'package:flutter_changdian_football/widget/screenutil/custom_screenutil.dart';
import 'package:get/route_manager.dart';

/// 搜索文本框
class SearchInputWidget extends StatelessWidget {
  const SearchInputWidget({
    super.key,
    this.hintText = '',
    this.radius = 6,
    this.controller,
    this.onSubmitted,
    this.isShowClose = false,
    this.onChange,
    this.onClose
  });

  final String hintText;

  final double radius;

  final TextEditingController? controller;

  final Function? onSubmitted;

  final bool isShowClose;
  final Function? onChange;
  final Function? onClose;

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 17.w),
      child: Row(
        children: [
          Expanded(
            child: Container(
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.circular(radius.r)
              ),
              padding: EdgeInsets.symmetric(horizontal: 20.w),
              child: Row(
                children: [
                  SizedBox(
                    width: 16.w,
                    height: 16.w,
                    child: Image.asset('assets/images/home_icon_ss.png'),
                  ),

                  SizedBox(width: 10.w,),

                  Expanded(
                    child: TextField(
                      style: TextStyle(fontSize: 14.sp, color: const Color(0xff333333)),
                      maxLines: 1,
                      keyboardType: TextInputType.text,
                      textInputAction: TextInputAction.search,
                      cursorColor: const Color(0xff61D25F),
                      controller: controller,
                      decoration: InputDecoration(
                        fillColor: Colors.transparent,
                        filled: true, 
                        counterText: "",
                        isCollapsed: true,
                        contentPadding: EdgeInsets.symmetric(vertical: 15.w),
                        border: InputBorder.none,
                        hintText: hintText,
                        hintStyle: TextStyle(fontSize: 14.sp, color: const Color(0xff727B7B)),
                      ),
                      onSubmitted: (p) {
                        onSubmitted?.call();
                      },
                      onChanged: (v) {
                        onChange?.call();
                      },
                    ),
                  ),

                  if (isShowClose == true) ...[
                    GestureDetector(
                      behavior: HitTestBehavior.translucent,
                      onTap: () {
                        FocusScope.of(Get.context!).requestFocus(FocusNode());
                        onClose?.call();
                      },
                      child: Container(
                        padding: EdgeInsets.all(4.w),
                        child: Icon(Icons.close, size: 18.w, color: const Color(0xffcccccc),),
                      ),
                    )
                  ]

                ],
              ),
            ),
          ),
        ],
      ),
    );
  }
}